<?php

class Silk_Tms_Model_Shipping_Order extends Mage_Core_Model_Abstract
{
	protected function _construct(){
       $this->_init("tms/shipping_order");
    }

	public function importData(Mage_Sales_Model_Order $order)
    {
		$this->setOrderId($order->getId());
		$this->setIncrementId($order->getIncrementId());
		$this->setStoreId($order->getStoreId());
		$this->setPlaceOrderTime($order->getCreatedAt());
		$this->setStatus('new');
		$this->setPickupAt(null);
		$this->setQtyOrdered($order->getQtyOrdered());
		$this->setSubtotal($order->getSubtotal());
		$this->setGrandTotal($order->getGrandTotal());
		$this->setDiscountAmount($order->getDiscountAmount());
		$this->setTotalPaid($order->getTotalPaid());
		$this->setTotalRefund($order->getTotalRefund());
		$this->setTotalItemCount($order->getTotalItemCount());
		$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
		$this->setCustomerId($order->getCustomerId());
		$this->setCustomerName($order->getShippingAddress()->getFirstname());
		$this->setCustomerStoreName($customer->getLastname());
		$this->setCustomerPhone($order->getShippingAddress()->getTelephone());
		$this->setCustomerAddress($order->getShippingAddress()->format('oneline'));
		return $this;
    }

	public function setStatusProcessing()
	{
		$this->setData('status', Silk_Tms_Helper_Status::STATUS_ORDER_PROCESSING);

		return $this;
	}

	public function setStatusPicked()
	{
		$this->setData('status', Silk_Tms_Helper_Status::STATUS_ORDER_PICKED);

		return $this;
	}

	public function setStatusDelivering()
	{
		$this->setData('status', Silk_Tms_Helper_Status::STATUS_ORDER_DELIVERING);

		return $this;
	}

	public function setStatusDelivered()
	{
		$this->setData('status', Silk_Tms_Helper_Status::STATUS_ORDER_DELIVERED);

		return $this;
	}

	public function setStatusCompleted()
	{
		$this->setData('status', Silk_Tms_Helper_Status::STATUS_ORDER_COMPLETED);

		return $this;
	}
}